/**
 * Copyright 2011 Alex Vikulov (vikuloff@gmail.com)

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */

package com.vvip.stockchart.series;


import com.vvip.stockchart.core.SeriesPaintInfo;
import com.vvip.stockhart.point.CustomPoint;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

public class LinearSeries extends AbstractSeries
{

	float prevX = Float.NaN;
	float prevY = Float.NaN;
	
	private int fLineColor = Color.RED;
	private float fLineWidth = 2.0f;
	


	private final Paint fPaint = new Paint();
	
	public LinearSeries() {
		super(1);
	}
	public int getfLineColor() {
		return fLineColor;
	}

	public void setLineColor(int v) {
		this.fLineColor = v;
	}

	public float getLineWidth() {
		return fLineWidth;
	}

	public void setLineWidth(float v) {
		this.fLineWidth = v;
	}
	@Override
	protected void drawPoint(Canvas c, SeriesPaintInfo pinfo, float x1, float x2, CustomPoint p) 
	{	
		float x = (x1 + x2)/2f;
		float y = pinfo.getY(p.Values[0]);
		
		if(0 != Float.compare(prevX, Float.NaN))
		{
			fPaint.setColor(fLineColor);
			fPaint.setStrokeWidth(fLineWidth);
			
			c.drawLine(prevX, prevY, x, y, fPaint);
		}
		
		prevX = x;
		prevY = y;

	}
	
	protected void preDraw() 
	{
		prevX = Float.NaN;
		prevY = Float.NaN;
	}

}
